<center>
<!DOCTYPE html>
<html>
 
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="message.css">
</head>
 
<body>

<h1>
    历史留言列表
</h1>
    <a href="history.php">刷新列表</a>
<hr style="width: 90%;"/>
<table border = "1" width = "700" >
    <tr>
        <th>用户名</th>
        <th>留言时间</th>
        <th>留言内容</th>
        <th>操作</th>
    </tr>

    <form action="exit.php" method="post">
    <input type="submit" value="退出登录"><br>
</form>

</body>

</html>

    <?php
 
header("Content-type: text/html; charset=utf-8");
 
// 创建连接
$conn = mysqli_connect('localhost', 'root', 'root','login');

if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}
 
$sql = "SELECT * FROM messages";
$result = $conn->query($sql);
 
if ($result->num_rows > 0) {
    // 输出数据
    while($row = $result->fetch_assoc()) {
        echo "<tr style='text-align: center'>";
        echo "<td>{$row["name"]}</td>";
        echo "<td>{$row["time"]}</td>";
        echo "<td>{$row["message"]}</td>";
        echo "<td><a href='delete.php?name=$row[name]&time=$row[time]'>删除</a></td>";
        echo "</tr>";
        echo "<br/>";
    }
}
else {
    echo "0 结果";
}
    $conn->close();
?>
</table>
</center>
